package com.example.wechathook.hook;

import static de.robv.android.xposed.XposedBridge.log;
import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.example.wechathook.util.WechatUtil;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

/**
 * 获取微信消息通知
 * 
 * @author chencq
 *
 */
public class NotifyRecevierHook extends BaseHook {

	@Override
	public void hook(XC_LoadPackage.LoadPackageParam lpp) {
		findAndHookMethod("com.tencent.mm.booter.NotifyReceiver", lpp.classLoader, "onReceive", Context.class,
				Intent.class, new XC_MethodHook() {
					@Override
					protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
						Context context = (Context) param.args[0];
						Intent intent = (Intent) param.args[1];
						Bundle bundle = intent.getExtras();
						if (bundle != null) {
							log("接收消息，时间:" + WechatUtil.getTime());
							log("消息[notify_uin]:" + bundle.get("notify_uin"));
							log("消息[notify_respType]:" + bundle.getInt("notify_respType"));// 268369921
							log("消息[notify_respBuf]:" + new String(bundle.getByteArray("notify_respBuf")));
						}
					}
				});
	}
}
